/**
 * 
 */
package leetCode;

/**
 * @author zhongfang
 *
 */
public class ConstructStringfromBinaryTree606 {
	  public class TreeNode {
		      int val;
		      TreeNode left;
		      TreeNode right;
		      TreeNode(int x) { val = x; }
		  }
    public String tree2str(TreeNode t) {
        if(t==null){
        	return "";
        }
        
        String string=""+t.val;
        if(t.left==null&&t.right==null){//00
        }else  if(t.left!=null&&t.right==null){//10
        	string+="("+tree2str(t.left)+")";
        }else{//01 11
        	string+="("+tree2str(t.left)+")";
        	string+="("+tree2str(t.right)+")";
		}
        return string;
    }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
